package com.ssm.util.test.encrypt;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.commons.codec.binary.Base64;

public class FileEncrypt {
	
    @SuppressWarnings("resource")
	public static void main(String[] args) {
    	try {
			FileInputStream in = new FileInputStream("D:/bootanimation.zip");
			byte[] buffer = new byte[in.available()];
			in.read(buffer);

			// BASE64加密
			byte[] data = Base64.encodeBase64(buffer);
			System.out.println("BASE64加密：" + new String(data));
			
			// BASE64解密
			byte[] bytes = Base64.decodeBase64(data);
//			System.out.println("BASE64解密：" + new String(bytes));
			File file = new File("D:/bskj/aaa.zip");
			file.createNewFile();
	    	ByteArrayOutputStream out = new ByteArrayOutputStream();
	    	out.write(bytes);
			FileOutputStream fileOutputStream = new FileOutputStream(file);
			fileOutputStream.write(out.toByteArray());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
